# -*- coding: utf-8 -*-
# @Time     : 2021/10/11 22:36
# @Author   : JustFly
# @File     : ts.py
# @Software : PyCharm

import requests
import json
import time
import pymysql
import traceback
from selenium import webdriver
def get_connphp():
    """
    :return: 连接, 游标
    """
    # 创建连接
    conn = pymysql.connect(host="127.0.0.1",
                           user="root",
                           password="123456",
                           db="covid_2019",
                           )
    # 创建游标
    cursor = conn.cursor()

    return conn, cursor
def get_conncts():
    """
    :return: 连接, 游标
    """
    # 创建连接
    conn = pymysql.connect(host="1.15.49.8",
                           user="root",
                           password="jjf521zl!",
                           db="covid_2019",
                           )
    # 创建游标
    cursor = conn.cursor()

    return conn, cursor

def close_conn(conn, cursor):
    if cursor:
        cursor.close()
    if conn:
        conn.close()

def querya(sql, *args):
    """
    封装通用查询
    :param sql:
    :param args:
    :return:元组
    """
    conn, cursor = get_connphp()
    cursor.execute(sql, args)
    res = cursor.fetchall()
    # print(res)
    close_conn(conn, cursor)
    return res
def queryb(sql, *args):
    """
    封装通用查询
    :param sql:
    :param args:
    :return:元组
    """
    conn, cursor = get_conncts()
    cursor.execute(sql, args)
    res = cursor.fetchall()
    # print(res)
    close_conn(conn, cursor)
    return res

conna, cursora = get_connphp()
connb, cursorb = get_conncts()

sqla = "select * from history"
data_a = querya(sqla)

for d in data_a:
    sqlb = "insert into history(ds, confirm, confirm_add, suspect, suspect_add, heal, heal_add, dead, dead_add)" \
           " values (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
    print(d[0])
    cursorb.execute(sqlb, d)
    connb.commit()

